from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
import uvicorn

app = FastAPI()

# 允许所有来源访问
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 允许的来源（这里是允许所有）
    allow_credentials=True,
    allow_methods=["*"],  # 允许的HTTP方法
    allow_headers=["*"],  # 允许的HTTP头
)

@app.get("/")
async def home():
    return {"user_id": 1002}


@app.get("/shop")
async def shop():
    return {"shoplist": ["apple", "banana", "orange"]}

@app.post("/send_command")
async def send_command(request: Request):
    data = await request.json()
    print(data)
    return {"status": "success", "message": "Command executed successfully."}


if __name__ == '__main__':
    uvicorn.run("quickstart:app", port=8081, log_level=True, reload=True)

